package Database;

import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JOptionPane;

public class EmployeeLogout {
	public EmployeeLogout(String empID)
	{
		try{
			Class.forName("com.mysql.jdbc.Driver");
			Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/library_community","root","1234");
			SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
			Date currentTime = new Date();
			String timeLogout = sdf.format(currentTime);        
			String query = "update lcmt_log_employee set LOG_EMPLOYEE_TIME_LOGOUT = ? where (EMPLOYEE_ID = ?) and (LOG_EMPLOYEE_TIME_LOGOUT is null)";
			PreparedStatement statement = con.prepareStatement(query);
			statement.setString(1, timeLogout);
			statement.setString(2, empID);
			statement.executeUpdate();
			statement.close();
			con.close();
		}catch(Exception e)
		{
			JOptionPane.showMessageDialog(null,e);
		}
	}
}
